package com.neuedu.oasystem.service.impl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.neuedu.oasystem.dao.IPrivilegeDao;

import com.neuedu.oasystem.dao.impl.PrivilegeDaoImpl;

import com.neuedu.oasystem.entity.Privilege;
import com.neuedu.oasystem.service.PrivilegeService;
import com.neuedu.oasystem.util.DBHelper;

public class PrivilegeServiceImpl implements PrivilegeService {
	private IPrivilegeDao privilegeDao;

	public PrivilegeServiceImpl() {
		super();
		this.privilegeDao = new PrivilegeDaoImpl();
	}

	@Override
	public boolean add(Privilege param) {
		Connection conn = DBHelper.openConnection();
		try {
			conn.setAutoCommit(false);
			privilegeDao.setConnection(conn);
			boolean ret = privilegeDao.add(param);
			conn.commit();
			conn.setAutoCommit(true);
			return ret;
		} catch (SQLException e) {
			if (conn != null) {
				try {
					conn.rollback();
					conn.setAutoCommit(true);
				} catch (SQLException e1) {
					e1.printStackTrace();
				}

			}
			e.printStackTrace();
		} finally {
			DBHelper.closeAll(null, null, conn);
		}
		return false;
	}

	@Override
	public boolean edit(Privilege param) {
		Connection conn = DBHelper.openConnection();
		try {
			conn.setAutoCommit(false);
			privilegeDao.setConnection(conn);
			boolean ret = privilegeDao.edit(param);
			conn.commit();
			conn.setAutoCommit(true);
			return ret;
		} catch (SQLException e) {
			if (conn != null) {
				try {
					conn.rollback();
					conn.setAutoCommit(true);
				} catch (Exception e2) {
				}
			}
			e.printStackTrace();
		} finally {
			DBHelper.closeAll(null, null, conn);
		}
		return false;
	}

	@Override
	public boolean deleteById(int id) {
		Connection conn = DBHelper.openConnection();
		try {
			conn.setAutoCommit(false);
			privilegeDao.setConnection(conn);
			boolean ret = privilegeDao.deleteById(id);
			conn.commit();
			conn.setAutoCommit(true);
			return ret;
		} catch (SQLException e) {
			if (conn != null) {
				try {
					conn.rollback();
					conn.setAutoCommit(true);
				} catch (Exception e2) {
				}
			}
			e.printStackTrace();
		} finally {
			DBHelper.closeAll(null, null, conn);
		}
		return false;
	}

	@Override
	public Privilege findById(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Privilege> findAll() {
		Connection conn = DBHelper.openConnection();
		try {
			privilegeDao.setConnection(conn);
			List<Privilege> list = privilegeDao.findAll();
			return list;
		} catch (Exception e) {
		} finally {
			DBHelper.closeAll(null, null, conn);
		}

		return null;
	}

	@Override
	public List<Privilege> findByExample(Privilege param) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Privilege> findByPager(int page, int size) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int deleteByIds(int[] ids) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int addAll(List<Privilege> useparamrs) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int editAll(List<Privilege> param) {
		// TODO Auto-generated method stub
		return 0;
	}

}
